﻿using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

public class ImageConversionService
{
    static async Task<string> DownloadImageAndConvertToBase64WithMimeAsync(string url)
    {
        using (HttpClient httpClient = new HttpClient())
        {
            httpClient.DefaultRequestHeaders.Add("User-Agent", "C# HttpClient");

            using (HttpResponseMessage response = await httpClient.GetAsync(url))
            {
                response.EnsureSuccessStatusCode();

                byte[] imageBytes = await response.Content.ReadAsByteArrayAsync();
                string mimeType = response.Content.Headers.ContentType?.MediaType ?? "application/octet-stream";
                string base64String = Convert.ToBase64String(imageBytes);

                return (base64String);
            }
        }
    }
}